package com.example.actionsignin.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.actionsignin.R;
import com.example.actionsignin.adapter.ManageAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 旭 on 2017/7/27/027.
 */

public class ManageFragment extends Fragment {

    private View view;

    private TabLayout tabLayout;
    private ViewPager viewPager;

    private List<Fragment> list_fragment = new ArrayList<>();
    private List<String> list_title = new ArrayList<>();

    private Fragment fragment_manage;
    private Fragment fragment_join;

    private ManageAdapter manageAdapter;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_manage,container,false);

        init();

        return view;
    }

    private void init() {
        tabLayout = (TabLayout) view.findViewById(R.id.manage_tableLayout);
        viewPager = (ViewPager) view.findViewById(R.id.manage_viewPager);

        fragment_manage = new MyManageFragment();
        fragment_join = new MyJoinFragment();

        list_title.add("我参加的");
        list_title.add("我发布的");

        list_fragment.add(fragment_join);
        list_fragment.add(fragment_manage);

        tabLayout.addTab(tabLayout.newTab().setText(list_title.get(0)));
        tabLayout.addTab(tabLayout.newTab().setText(list_title.get(1)));

        manageAdapter = new ManageAdapter(getActivity().getSupportFragmentManager(),list_fragment,list_title);

        viewPager.setAdapter(manageAdapter);
        tabLayout.setupWithViewPager(viewPager);

    }
}
